package com.wuxianedu.broadcastreceiver3;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

/**
 * Created by TED on 2016/9/23.
 */
public class OtherActivity extends AppCompatActivity {

    private LocalBroadcastManager lbm;
    private LocalReceiver receiver;
    private EditText et;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);

        et = (EditText) findViewById(R.id.et);

        lbm = LocalBroadcastManager.getInstance(this);
//        receiver = new LocalReceiver();
//        IntentFilter filter = new IntentFilter();
//        filter.addAction("com.wuxianedu.action.LOCAL");
//        lbm.registerReceiver(receiver,filter);
    }

    public void send(View view) {
        if (TextUtils.isEmpty(et.getText().toString())){
            return;
        }


        Intent intent = new Intent();
        intent.putExtra("et",et.getText().toString());
        intent.setAction("com.wuxianedu.action.LOCAL");
        lbm.sendBroadcast(intent);
    }

    @Override
    protected void onDestroy() {
       // lbm.unregisterReceiver(receiver);
        super.onDestroy();
    }
}
